fix(security): CORS restrito para dev web (correção face ao PR #23)#42
Draft
dbfcode wants to merge 1 commit into
Draft
fix(security): CORS restrito para dev web (correção face ao PR #23)#42dbfcode wants to merge 1 commit into
dbfcode wants to merge 1 commit into
Conversation
Co-authored-by: Diêgo Ferreira <dbfcode@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contexto (PR #23)
No branch
homepage/ PR #23, oSecurityConfigpassa a registar CORS comsetAllowedOriginPatterns(Arrays.asList("*"))esetAllowCredentials(true). Essa combinação é incompatível com a especificação CORS: com credenciais ativas, o navegador não aceita*como origem, pelo que pedidos cross-origin (comofetch("http://localhost:8080/products")a partir dehttp://localhost:5173) podem falhar de forma intermitente ou sistemática.O hook do PR chama a API diretamente em
http://localhost:8080, logo o CORS do Spring passa a ser relevante. Hot reload (Vite HMR e Spring DevTools) não depende destes headers CORS; não há impacto esperado na infra de back-end ou nos volumes do compose.Alteração (mínima)
SecurityConfig.java..cors(...)com origens explícitas alinhadas ao compose atual: Vite em 5173 e serviço web (nginx) em 4173, emlocalhoste127.0.0.1.allowCredentials(false)— alinhado ao cliente atual emmain(credentials: 'omit'emweb/src/lib/api.ts) e aofetchdo PR semcredentials: 'include'.Nota para o PR #23
springdoc-openapinopom.xml; emmainisso já existe — ao integrar, convém não duplicar o bloco nopom.xml./api/products(proxy do Vite) elimina CORS no browser em dev; mesmo assim, o CORS restrito aqui é uma rede de segurança razoável.Verificação
./mvnw testna pastaapi/concluído com sucesso.